package com.feonix.redis.pipeline;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

public class PipelineTest {

	@SuppressWarnings("unchecked")
	@Test
	public void test() {
		ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
				"spring-context-jedis.xml");
		RedisTemplate<String, List<String>> redisTemplate = applicationContext.getBean("jedisTemplate",
				RedisTemplate.class);
		final RedisSerializer<String> serializer = redisTemplate.getStringSerializer();   
		List<Object> lists = redisTemplate.executePipelined(new RedisCallback<String>() {

			public String doInRedis(RedisConnection connection) throws DataAccessException {
				for (int i = 0; i < 10; i++) {
					connection.lPush(serializer.serialize("testlpush"), serializer.serialize("testlpush"+i));
				}
				
				return null;
			}
		});
		lists.stream().forEach(System.out::println);
		applicationContext.close();
	}

}
